<template>
	<view>
		<template v-if="messageTime.mode=='time'">
			<u-datetime-picker cancelText="取消" confirmText="確認" :show="messageTime.timeShow" :minDate="messageTime.minDate || 0" :title="messageTime.title"
				:mode="messageTime.mode" @cancel="cancel" @confirm="confirm"></u-datetime-picker>
		</template>
		<template v-else>
			<u-datetime-picker cancelText="取消" confirmText="確認" :show="messageTime.timeShow" :minDate="messageTime.minDate || 0" v-model="value1" :title="messageTime.title"
				:mode="messageTime.mode" @cancel="cancel" @confirm="confirm"></u-datetime-picker>
		</template>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		name: "timePicker",
		props:{
			messageTime:{}
		},
		data() {
			return {
				value1:Number(new Date())
			};
		},
		methods:{
			confirm(e){
				if(this.messageTime.mode=="date"){//年月日
					this.$emit("timeConfirm",httpRequest.returnDate(e.value))
				}else if(this.messageTime.mode=="datetime"){//年月日时分秒
					this.$emit("timeConfirm",this.timereturn(e.value))
				}else if(this.messageTime.mode=="time"){//时分
					this.$emit("timeConfirm",e.value)
				}
				this.messageTime.timeShow = false
			},
			cancel(e){
				this.messageTime.timeShow = false
			},
			timereturn(time3){
				      //将时间戳格式转换成年月日时分秒
				      var date = new Date(time3);
				      var Y = date.getFullYear() + '-';
				      var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
				      var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
				
				      var h = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours()) + ':';
				      var m = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes()) + ':';
				      var s = (date.getSeconds() < 10 ? '0' + (date.getSeconds()) : date.getSeconds());
				      var strDate = Y + M + D + h + m + s;
					  return strDate

			},
		}
	}
</script>

<style>

</style>